package com.oliet.common.result;

import lombok.Builder;
import lombok.Data;
import org.apache.poi.ss.formula.functions.T;

/**
 * @author jiaZhenpeng
 * @Title: CommonResponse
 * @Package com.oliet.common.result
 * @Description: 通用返回
 * @date 2023-11-26 16:06
 */
@Data
@Builder
public class CommonResponse<T> {


    private Boolean result;
    private String code;
    private String msg;
    private T data;

    public static <T> CommonResponse success() {
        return CommonResponse.<T>builder().result(true).code("2000").msg("操作成功").data(null).build();
    }

    public static <T> CommonResponse<T> data(T data) {
        return CommonResponse.<T>builder().result(true).code("2000").msg("操作成功").data(data).build();
    }

    public static <T> CommonResponse fail() {
        return CommonResponse.<T>builder().result(false).code("5001").msg("操作失败").data(null).build();
    }

    public static <T> CommonResponse fail(String message) {
        return CommonResponse.<T>builder().result(false).code("5001").msg(message).data(null).build();
    }

    public static <T> CommonResponse fail(String message, T data) {
        return CommonResponse.<T>builder().result(false).code("5001").msg(message).data(data).build();
    }

    public static <T> CommonResponse error(String code, String message) {
        return CommonResponse.<T>builder().result(false).code(code).msg(message).data(null).build();
    }

    public static <T> CommonResponse error( String message) {
        return CommonResponse.<T>builder().result(false).code("5001").msg(message).data(null).build();
    }

    public static <T> CommonResponse error(String code, String message, T data) {
        return CommonResponse.<T>builder().result(false).code(code).msg(message).data(data).build();
    }

}
